package FriendTable.Gui;
/*
更新A
 */

import FriendTable.FriendDAO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DeletePanel extends JPanel {
    private InputPanel idInput;
    private JButton deleteButton;
    private JTextArea resultArea;


    public DeletePanel() {

        setLayout(new GridLayout(4, 2));

        idInput = new InputPanel("ID:", null);
        add(idInput);

        deleteButton = new JButton("删除");
        add(deleteButton);

        resultArea = new JTextArea();
        add(resultArea);

        deleteButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int id;
                try {
                    id = Integer.parseInt(idInput.textField.getText());
                } catch (NumberFormatException ex) {
                    JOptionPane.showMessageDialog(null, "请输入有效的ID！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }

                FriendDAO.deleteFriend(id);
                resultArea.setText("删除成功！");
                FriendGUI.refreshFriendsList();
            }
        });
    }
}